﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FinosAdmin.Logics;
using Microsoft.Win32;
using FinosLibrary;
using System.Diagnostics;
using System.Reflection;
namespace FinosAdmin {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            //textBox2.InputScope = new InputScope() { RegularExpression = @"[a-zA-Z0-9]+" };
            ellipse1.DataContext = button5.DataContext = this.GetInstance<Other>();
            button1.DataContext = comboBox1.DataContext = this.GetInstance<Server>();
            comboBox1.SelectedIndex = 0;
            Title += "  " + Assembly.GetExecutingAssembly().FullName.Split(',')[1];
            DataContext = this.GetInstance<AppInfo>();
        }
        private void button6_Click(object sender, RoutedEventArgs e) {
            if (MessageBox.Show("确定删除该模块？", "删除前确认", MessageBoxButton.OKCancel) == MessageBoxResult.OK) {
                NetConnection.doLogic("DeleteApp");
            }
        }

        private void button_Click(object sender, RoutedEventArgs e) {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.FileOk += (object s, System.ComponentModel.CancelEventArgs ee) => {
                textBox.Text = dialog.FileName;
            };
            dialog.Filter = "模块(*.dll)|*.dll";
            dialog.ShowDialog();
        }

        private void button3_Click(object sender, RoutedEventArgs e) {
            string currentApp = textBox2.Text.Split('/')[0];
            ModelLogic.doLogic("CreateApp", new string[] { currentApp, textBox.Text });
        }

        private void button1_Click(object sender, RoutedEventArgs e) {
            if (comboBox1.IsEnabled) {
                NetConnection.getInstance().Connect(comboBox1.Text);
                if (comboBox1.SelectedIndex == -1) {
                    NetConnection.doLogic("AddServerAddress", comboBox1.Text);
                }
            } else {
                NetConnection.getInstance().close();
            }
        }

        private void button5_Click(object sender, RoutedEventArgs e) {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.FileName = "FinosSDK.rar";
            dialog.FileOk += (object s, System.ComponentModel.CancelEventArgs ee) => {
                NetConnection.doLogic("GetSDK", dialog.FileName);
            };
            dialog.ShowDialog();
        }

        private void button2_Click(object sender, RoutedEventArgs e) {
            this.GetInstance<Server>().call("Restart");
        }

        private void button8_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ServerInfo.Open();
        }

        private void button8_Copy_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            new About().ShowDialog();
        }
    }
}
